<?php

/**
 * Z-Blog with PHP.
 *
 * @author  Z-BlogPHP Team
 * @version 2.0 2013-07-05
 */
require '../function/c_system_base.php';
require '../function/c_system_admin.php';

$zbp->Load();

$action = 'KeywordsPst';
if (!$zbp->CheckRights($action)) {
    $zbp->ShowError(6, __FILE__, __LINE__);
    die();
}

$blogtitle = $lang['msg']['keywords_edit'];




$keywordsid = null;
if (isset($_GET['id'])) {
    $keywordsid = (int) GetVars('id', 'GET');
    $action = 'KeywordsEdt';
    if (!$zbp->CheckRights($action)) {
        $zbp->ShowError(6, __FILE__, __LINE__);
        die();
    }
} else {
    $keywordsid = 0;
    $action = 'KeywordsNew';
    if (!$zbp->CheckRights($action)) {
        $zbp->ShowError(6, __FILE__, __LINE__);
        die();
    }
}
$keywords= $zbp->GetKeywordByID($keywordsid);
require ZBP_PATH . 'zb_system/admin/admin_header.php';
require ZBP_PATH . 'zb_system/admin/admin_top.php';
?>

<div id="divMain">
    <div class="divHeader2">
        <?php echo $lang['msg']['keywords_edit']; ?></div>
    <div class="SubMenu">
        <?php
        HookFilterPlugin('Filter_Plugin_Keyword_Edit_SubMenu');
        ?>
    </div>
    <div id="divMain2"  class="edit keywords_edit">
        <form id="edit" name="edit" method="post" action="#">
            <input id="edtID" name="ID" type="hidden" value="
            <?php
            echo $keywords->ID;
            ?>
            " />
            <div id="carea" style="margin:5px 0 0 0" class="editmod editmod3">
                <textarea id="editor_keywords" rows="25%" cols="100%" name="Keywords" style="padding: 10px"><?php echo FormatString($keywords->Keywords, '[html-format]');?></textarea>
            </div>
            <p style="">
                <span class='title'>
                    当前有<span id="lineCountDisplay">0</span>行关键字
                </span>
            </p>
            <p>
                <span class='title'>
                    <?php echo $lang['msg']['article_category']; ?>: 多个用类似1,2,3分开</span>
                <br />
                <input id="edtCategory" class="edit" size="40" name="Category" type="text" value="<?php if ($keywords->Category) echo $keywords->Category;else echo "1,2"; ?>" autocomplete="off" />
            </p>
            <p>
                <input type="submit" class="button" value="保存并发送" id="btnPost" onclick="return checkInfo();" />
                <input type="submit" class="button" value="只保存不发送" id="btnPost" onclick="return SaveInfo();" />
            </p>
        </form>

        <script>
            function checkInfo() {
                document.getElementById("edit").action = "<?php echo BuildSafeCmdURL('act=KeywordsPst'); ?>";
                if (!$("#editor_keywords").val()) {
                    alert("<?php echo $lang['error']['72']; ?>");
                    return false
                }
            }
            function SaveInfo() {
                document.getElementById("edit").action = "<?php echo BuildSafeCmdURL('act=KeywordsPst&NotSend=1'); ?>";
                if (!$("#editor_keywords").val()) {
                    alert("<?php echo $lang['error']['72']; ?>");
                    return false
                }
            }

            document.addEventListener('DOMContentLoaded', function() {
                var textarea = document.getElementById('editor_keywords');
                var lineCountDisplay = document.getElementById('lineCountDisplay');

                // 函数用于更新行数显示
                function updateLineCount() {
                    // 获取 textarea 的内容并按行分割
                    var lines = textarea.value.split('\n');
                    // 过滤掉空行
                    var nonEmptyLines = lines.filter(function(line) {
                        return line.trim() !== '';
                    });
                    // 计算非空行的数量
                    var lineCount = nonEmptyLines.length;
                    lineCountDisplay.innerText = lineCount;
                }

                // 添加 input 事件监听器
                textarea.addEventListener('input', updateLineCount);

                // 页面加载时获取初始内容并更新行数
                updateLineCount();
            });



        </script>
        <script>
            ActiveLeftMenu("aKeywords");
        </script>
        <script>
            AddHeaderIcon("<?php echo $zbp->host . 'zb_system/image/common/new_32.png'; ?>");
        </script>
        <script>
            AddHeaderFontIcon("icon-fonts");
        </script>
    </div>

</div>
<?php
require ZBP_PATH . 'zb_system/admin/admin_footer.php';

RunTime();